package com.eop.managedBean;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.component.form.impl.UICombo;
import org.operamasks.faces.user.util.Browser;

import com.base.common.provider.CommonKeySelectItemProvider;
import com.base.utils.IdUtils;
import com.eop.entity.Schnario;

@ManagedBean(name = "eop_addSchnarioBean", scope = ManagedBeanScope.REQUEST)
public class AddSchnarioBean extends BaseSchnarioBean {
	@Inject
	private FacesContext context;
	@Bind(id = "srRangeBigType", attribute = "binding")
	private UICombo srRangeBigType_binding;

	@Bind(id = "srRangeThinType", attribute = "binding")
	protected UICombo srRangeThinType_binding;
	@SaveState
	private String first;

	@BeforeRender
	public void beforeRender(boolean isPostback) {
		if (!isPostback) {
			id = IdUtils.getUUID();
			srVersion = "1.0";
		}
	}

	@Action(id = "srRangeBigType", event = "onselect", immediate = true)
	public void changeSrRangeBigType() {
		first = srRangeBigType_binding.getSubmittedValue().toString().trim();
		srRangeThinType_items = CommonKeySelectItemProvider.getDirectCommonKey(
				first, false);
	}

	@Action(id = "save")
	public void save() {
		sr = new Schnario();
		srVersion = "1.0";
		sr.setSrVersion(srVersion);
		this.setSchnarioProperty();
		schnarioService.saveSchnario(sr);
		Browser
				.execClientScript("javascript:closeCenterLayoutTab('addSchnarioTab')");

	}

}
